package br.com.cadele.dao;

import java.io.Serializable;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class BaseDao implements Serializable{
	private static final long serialVersionUID = 1311969814357797832L;
	private static Connection con = null;
	
	protected BaseDao(){
		connect();
	}
	
	private void connect() {
		String url = "jdbc:mysql://"+"localhost"+":3306/cadele";
		String user = "root";
		String pass = "";
		try {
			Class.forName("com.mysql.jdbc.Driver");
			con = DriverManager.getConnection(url,user,pass);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public ResultSet getQueryResultSet(String sql){
		try {
			Statement stm = con.createStatement(); 
			ResultSet rs = stm.executeQuery(sql);
			return rs; 
		} catch(SQLException e) {
			System.out.print("Erro ao executar Query!");
			e.printStackTrace();
			return null;
		}
	}
	
	public void executeSQL(String sql){
		try {
			Statement stm = con.createStatement();
			stm.execute(sql); 
		} catch(SQLException e) {
			System.out.print("Erro ao executar Query!");
			e.printStackTrace();
		} 
	}
	
	
}
